window.onload = function () {
    //获取浏览器的query参数
    function getUrlParams() {
        let href = location.href;
        let regExp = /.+\?(.+)/
        let param = regExp.exec(href)[1]
        let paramArr = param.split("&");
        let query = {}
        paramArr.forEach(item => {
            let itemArr = item.split("=");
            query[itemArr[0]] = decodeURI(itemArr[1])
        })

        return query
    }
    //获取浏览器query参数
    let query = getUrlParams() 
    console.log(query);
    let brandtitleid=query.brandTitleId;
    let title=query.title;
    let aTitle=document.querySelector(".title");
    aTitle.innerText=title;
    // console.log(brandtitleid)
    //根据获得的参数进行数据请求
    let html="";
    ajax({
        url: "http://chst.vip:1234/api/getbrandproductlist",
        data: {
            brandtitleid:brandtitleid ,
            pagesize: 10
        }
    }).then(res=>{
        let resArr=res.result;
        console.log(resArr);
        //根据请求结果渲染页面
        resArr.forEach(item=>{
            html+=`<li>
                 <a href="./brandproductcom.html?productId=${item.productId}&categoryId=${item.categoryId}&brandTitleId=${item.brandTitleId}">
                <div class="left">
                    ${item.productImg}
                </div>
                <div class="right">
                    <h4>${item.productName}</h4>
                    <p class="p1">${item.productPrice}</p>
                    <div class="bottom">
                    <span class="span1">${item.productQuote}</span>
                    <span class="span2">${item.productCom}</span>
                    </div>
                </div>
                </a>
                </li>`
        })
        let ul=document.querySelector(".ul-box");
        ul.innerHTML=html;
    })
}
